package com.mkj.basic;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

/**
 * @Author Arrebol
 * @Date 2024/8/6 18:30
 * @Project graphical programming
 * @Description：
 * 选项对话框演示
 */
public class OptionDialogTest {

    private final JFrame frame = new JFrame("测试选项对话框");
    private JTextArea textArea = new JTextArea(6,30);
    private JButton button = new JButton(new AbstractAction("弹出选项对话框") {
        @Override
        public void actionPerformed(ActionEvent e) {
            int result = JOptionPane.showOptionDialog(frame,"请选择型号",
                    "选项对话框",JOptionPane.DEFAULT_OPTION,JOptionPane.INFORMATION_MESSAGE,null,
                    new String[]{"Large","Medium","Tiny"},"Medium");
            switch (result){
                case 0:
                    textArea.append("Large");
                    textArea.append("\n");
                    break;
                case 1:
                    textArea.append("Medium");
                    textArea.append("\n");
                    break;
                case 2:
                    textArea.append("Tiny");
                    textArea.append("\n");
                    break;
            }
        }
    });
    public void init(){
        //组装视图
        frame.add(textArea);
        frame.add(button,BorderLayout.SOUTH);
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
    public static void main(String[] args) {
        new OptionDialogTest().init();
    }
}
